package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_BianJi_ServiceActivity;
import com.example.xianji.activity.Main_FuWu_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.Service;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Service_Adapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<Service> list;

    public Service_Adapter(Context mContext, ArrayList<Service> list) {
        super();
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(mContext, R.layout.service_listview_item, null);
            mHolder.service_title = (TextView) convertView.findViewById(R.id.service_title);
            mHolder.service_time = (TextView) convertView.findViewById(R.id.service_time);
            mHolder.text_bianji = (ImageView) convertView.findViewById(R.id.text_bianji);
            //mHolder.Relative_text_bianji=(RelativeLayout) convertView.findViewById(R.id.Relative_text_bianji);
            convertView.setTag(mHolder);
        }
        mHolder = (Holder) convertView.getTag();

        mHolder.service_title.setText(list.get(position).getTitle());
        mHolder.service_time.setText(list.get(position).getCreated_at());
        final int a = position;

        mHolder.text_bianji.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, Main_BianJi_ServiceActivity.class);
                intent.putExtra("caseId", list.get(a).getId());
                mContext.startActivity(intent);
            }
        });

        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, Main_FuWu_DetailsActivity.class);
                intent.putExtra("fuwu_details_id", list.get(a).getId());
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }

    class Holder {
        TextView service_title;
        TextView service_time;
        ImageView text_bianji;
    }
}
